<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>后台管理系统-登录</title>
    <link rel="stylesheet" type="text/css" href="/static/backend/layui/css/layui.css" media="all" />
    <link rel="stylesheet" type="text/css" href="/static/backend/css/login.css" />
</head>
<body class="beg-login-bg">
    <div class="beg-login-box">
        <header>
            <h1>后台管理系统</h1>
        </header>
        <div class="beg-login-main">
            <form action="login.html" class="layui-form" method="post">
                <div class="layui-form-item">
                    <label class="beg-login-icon">
                        <i class="layui-icon">&#xe612;</i>
                    </label>
                    <input type="text" lay-verify="required" id='username' name="name" autocomplete="off" placeholder="这里输入账号" class="layui-input" lay-verType="tips">
                </div>
                <div class="layui-form-item">
                    <label class="beg-login-icon">
                        <i class="layui-icon">&#xe642;</i>
                    </label>
                    <input type="password" lay-verify="required" id='password' name="password" autocomplete="off" placeholder="这里输入密码" class="layui-input" lay-verType="tips">
                </div>
                <div class="layui-form-item">
                    <div class="beg-pull">
                        <button type="button" class="layui-btn layui-btn-normal btn" style="width:100%;" lay-submit lay-filter="formDemo">
                            登　　录
                        </button>
                    </div>
                </div>
            </form>
        </div>
        <footer>
            <p>power by 科技 © </p>
        </footer>
    </div>
    <script type="text/javascript" src="/static/backend/javascript/jquery.min.js"></script>
    <script type="text/javascript" src="/static/backend/layui/layui.js"></script>
    <script type="text/javascript" src="/static/backend/javascript/login.js"></script>
    <script>
        var layer;
        $(".btn").click(function(){
            var userName = $("#username").val();
            var password = $("#password").val();
            if(userName==""){
                layui.use('layer', function(){
                    layer = layui.layer;
                    layer.tips('账号不能为空', '#username');
                });
                return;
            }
            if(password==""){
                layui.use('layer', function(){
                    layer.tips('密码不能为空', '#password');
                });
                return;
            }
            
           /* if(captcha==""){
                layui.use('layer', function(){
                    layer.tips('验证码不能为空', '#captcha');
                });
                return;
            }*/

            $.ajax({
                type: "POST",
                url: "{:url('login/check')}",
                data: {
                    name:userName,
                    password:password
                },
                dataType: "json",
                success: function(data){
                    // console.log(data)
                    if(data.code==1){
                        layui.use('layer', function(){
                            layer.msg('登录成功', {
                                icon: 1,
                                time: 2000,
                                end:function(){
                                    location.href="{:url('admin/index')}";
                                }
                            });
                        });
                    }else{
                        layui.use('layer', function(){
                            layer.msg(data.msg,{
                                icon:2
                            });
                        });
                        return;
                    }
                }
            })
        })
    </script>
    </body>
</html>